{{include_file name='public/header' title='数据库备份/还原'}}
<style>
    .table {
        width: 100%;
        max-width: 100%;
        margin-bottom: 0;
    }
</style>
</head>

<body>

<div id="wrapper">

    <!-- Navigation -->
    {{include_file name='public/nav' sidebar='sidebar'}}
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <div class="page-header">
                    <h1>数据库备份 </h1>
                    <div class="opt-btn">
                        <a href="javascript:void(0);" class="btn btn-sm btn-warning js_backupBtn" data-placement="bottom" data-id="26">备份</a>
                    </div>
                </div>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->

        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-default">

                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>#</th>
                                    <th>文件名</th>
                                    <th>文件大小</th>
                                    <th>备份时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                {{foreach $dbbaks as $k=>$dbbak}}

                                <tr>
                                    <td>{{$k+1}}</td>
                                    <td>{{$dbbak.file}}</td>
                                    <td>{{$dbbak.size}}KB</td>
                                    <td>{{$dbbak.add_time}}</td>
                                    <td style="width: 25%;">
                                        <a href="{{url("admin/db/download")}}?id={{$dbbak.id}}" class="btn btn-warning btn-xs" data-id="{{$dbbak.id}}">下载文件</a>
                                        <button type="button" class="btn btn-danger btn-xs js_deleteBtn" data-id="{{$dbbak.id}}">删除文件</button>
                                        <button type="button" class="btn btn-success btn-xs js_restoreBtn" data-id="{{$dbbak.id}}">还原数据</button>
                                    </td>
                                </tr>

                                {{/foreach}}
                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
            </div>
            <!-- /.panel -->
            <div class="col-sm-12">
                {{include_file name='public/page'}}
            </div>
        </div>

        <!-- 还原模态框 -->
        <div class="modal fade" id="js_restoreDbModal" tabindex="-9" role="dialog">
            <div class="modal-dialog" role="document">

                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">还原数据</h4>
                    </div>
                    <div class="modal-body">

                        <iframe id="js_restoreDbIframe" style="min-height: 450px;" src="{{url('admin/db/restore')}}"></iframe>

                    </div>

                </div>

            </div>

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <hr>
    <p class="text-center">{{get_config('copyright')}}</p>
    <script>
        $(function () {
            // 备份
            $(".js_backupBtn").click(function () {
                var url = "{{url('admin/db/backup')}}";
                $.post(url, {}, function(json){

                    alert(json.msg, 1000, function(){

                        window.location.reload();

                    });

                }, 'json');
            });
            // 删除文件
            $(".js_deleteBtn").click(function () {
                var thisObj = $(this);
                var url = "{{url('admin/db/delete')}}";
                var id  = thisObj.data('id');

                confirm('确认要删除备份文件?', function(){

                    $.post(url, { id:id }, function(json){

                        if(json.code == 200){

                            alert(json.msg, 500, function () {
                                thisObj.closest('tr').remove();
                            });

                        }else{

                            alert(json.msg, 2000);

                        }

                    }, 'json');
                });

            });

            // 还原数据
            $(".js_restoreBtn").click(function () {

                var thisObj       = $(this);
                var restoreModal  = $("#js_restoreDbModal");

                var iframeSrc     = "{{url('admin/db/restore')}}" + "?id=" + thisObj.data('id');

                confirm('确认要将数据还原?', function(){

                    restoreModal.find('iframe').attr('src', iframeSrc);

                    setTimeout(function () {
                        restoreModal.modal('show');
                    }, 200);

                });

            });
        });
    </script>
    {{include_file name='public/footer'}}
